package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Device;
import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;

/**
 * <p>
 * WorkRecord实体.
 * </p>
 * 工作记录
 */
@Entity()
@Table(name = "T_WORKREC")
@BatchSize(size = 20)
@Lazy(value = true)
public class WorkRecord extends BasicModel implements java.io.Serializable {

	public final static int FORCE_CHANGE_PRIORITY = 901; // 强制修改零件任务优先级
	public final static int CANCEL_PART_TASK = 902; // 强制取消零件任务
	public final static int FORCE_FINISH_TASK = 903; // 强制修改零件任务优先级
	public final static int FORCE_NOT_FINISH_TASK = 904; // 强制修改零件任务优先级
	public final static int WORKTYPE_MODIFY_PART_TASK_PLANQTY = 905; // 修改零件任务在制数量
	public final static int FORCE_FINISH_TASK_NO_COMPLETEQTY = 906; // 由工人数量问题引起的强制完成

	public final static int COMPLETESTATE_DRAFT = 1; // 草稿
	public final static int COMPLETESTATE_SUBMITCHECK = 2; // 已交捡
	public final static int COMPLETESTATE_CHECKED = 4; // 已检验
	public final static int COMPLETESTATE_VALID = 6; // 已检验

	@Id
	@GenericGenerator(name = "uniqueId", strategy = "assigned")
	@Column(name = "UNIQUE_ID", unique = true)
	private String uniqueId;

	@Column(name = "RESUID")
	protected String deviceUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RESUID", insertable = false, updatable = false)
	protected Device device;

	@Column(name = "TASKUID")
	protected String taskUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TASKUID", insertable = false, updatable = false)
	protected OperationTask operationTask;

	@Column(name = "EMPLOYEEID")
	protected String workerUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "EMPLOYEEID", insertable = false, updatable = false)
	protected Employee worker;

	@Column(name = "MATERIALUSN")
	protected String materialUsn;

	@Column(name = "WORKTYPE")
	protected Integer workType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'worktype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData workTypeDesc;

	@Column(name = "WORKDATE")
	protected Date workDate;

	@Column(name = "SHIFTID")
	protected String shiftId;

	@Column(name = "COMPLETEPERCENT")
	protected Float completePercent;

	@Column(name = "COMPLETEQTY")
	protected Float completeQty;

	@Column(name = "COMPLETEWORK")
	protected Float completeWork;

	// 合格数
	@Column(name = "CHECK1QTY")
	protected Float passingQty;

	// @Column(name = "CHECK2QTY")
	// protected Float check2Qty;

	// 报废书
	@Column(name = "CHECK8QTY")
	protected Float check8Qty;

	@Column(name = "CHECKER")
	protected String checkerUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CHECKER", insertable = false, updatable = false)
	protected Employee checker;

	@Column(name = "CHECKDATE")
	protected Date checkDate;

	@Column(name = "CHECKNOTES")
	protected String checkNotes;

	@Column(name = "ASSNUID")
	protected String assignmnetUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ASSNUID", insertable = false, updatable = false)
	private AssignmentDevice assignmentDevice;

	@Column(name = "COMPLETESTATE")
	protected Integer completeState;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'completestate'", referencedColumnName = "TYPESNAME")) })
	protected TypesData completeStateDesc;

	@Column(name = "OPTYPE")
	protected String opType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'optype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData opTypeDesc;

	@Column(name = "MANHOURTYPE")
	protected String manhourType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'manhourtype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData manhourTypeDesc;

	@Column(name = "ACTUALWORK")
	protected Float actualWork;

	@Column(name = "PREOPTIME")
	protected Float preopTime;

	@Column(name = "RUNTIME")
	protected Float runTime;

	@Column(name = "DISPATCHTYPE")
	protected String dispatchType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MANHOURSTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'dispatchtype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData dispatchTypeDesc;

	@Column(name = "APPLYWORK")
	protected Float applyWork;

	/**
	 * 空的构造函数
	 */
	public WorkRecord() {
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getUniqueId();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setUniqueId(uuid);
	}
	
	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public String getDeviceUid() {
		return deviceUid;
	}

	public void setDeviceUid(String deviceUid) {
		this.deviceUid = deviceUid;
	}

	public Device getDevice() {
		return device;
	}

	public void setDevice(Device device) {
		this.device = device;
	}

	public String getTaskUid() {
		return taskUid;
	}

	public void setTaskUid(String taskUid) {
		this.taskUid = taskUid;
	}

	public OperationTask getOperationTask() {
		return operationTask;
	}

	public void setOperationTask(OperationTask operationTask) {
		this.operationTask = operationTask;
	}

	public String getWorkerUid() {
		return workerUid;
	}

	public void setWorkerUid(String workerUid) {
		this.workerUid = workerUid;
	}

	public Employee getWorker() {
		return worker;
	}

	public void setWorker(Employee worker) {
		this.worker = worker;
	}

	public String getMaterialUsn() {
		return materialUsn;
	}

	public void setMaterialUsn(String materialUsn) {
		this.materialUsn = materialUsn;
	}

	public Integer getWorkType() {
		return workType;
	}

	public void setWorkType(Integer workType) {
		this.workType = workType;
	}

	public TypesData getWorkTypeDesc() {
		return workTypeDesc;
	}

	public void setWorkTypeDesc(TypesData workTypeDesc) {
		this.workTypeDesc = workTypeDesc;
	}

	public Date getWorkDate() {
		return workDate;
	}

	public void setWorkDate(Date workDate) {
		this.workDate = workDate;
	}

	public String getShiftId() {
		return shiftId;
	}

	public void setShiftId(String shiftId) {
		this.shiftId = shiftId;
	}

	public Float getCompletePercent() {
		return completePercent;
	}

	public void setCompletePercent(Float completePercent) {
		this.completePercent = completePercent;
	}

	public Float getCompleteQty() {
		return completeQty;
	}

	public void setCompleteQty(Float completeQty) {
		this.completeQty = completeQty;
	}

	public Float getCompleteWork() {
		return completeWork;
	}

	public void setCompleteWork(Float completeWork) {
		this.completeWork = completeWork;
	}

	public Float getPassingQty() {
		return passingQty;
	}

	public void setPassingQty(Float passingQty) {
		this.passingQty = passingQty;
	}

	public Float getCheck8Qty() {
		return check8Qty;
	}

	public void setCheck8Qty(Float check8Qty) {
		this.check8Qty = check8Qty;
	}

	public String getCheckerUid() {
		return checkerUid;
	}

	public void setCheckerUid(String checkerUid) {
		this.checkerUid = checkerUid;
	}

	public Employee getChecker() {
		return checker;
	}

	public void setChecker(Employee checker) {
		this.checker = checker;
	}

	public Date getCheckDate() {
		return checkDate;
	}

	public void setCheckDate(Date checkDate) {
		this.checkDate = checkDate;
	}

	public String getCheckNotes() {
		return checkNotes;
	}

	public void setCheckNotes(String checkNotes) {
		this.checkNotes = checkNotes;
	}

	public String getAssignmentUid() {
		return assignmnetUid;
	}

	public void setAssignmentUid(String assignmnetUid) {
		this.assignmnetUid = assignmnetUid;
	}

	public AssignmentDevice getAssignmentDevice() {
		return assignmentDevice;
	}

	public void setAssignmentDevice(AssignmentDevice assignmentDevice) {
		this.assignmentDevice = assignmentDevice;
	}

	public Integer getCompleteState() {
		return completeState;
	}

	public void setCompleteState(Integer completeState) {
		this.completeState = completeState;
	}

	public TypesData getCompleteStateDesc() {
		return completeStateDesc;
	}

	public void setCompleteStateDesc(TypesData completeStateDesc) {
		this.completeStateDesc = completeStateDesc;
	}

	public String getOpType() {
		return opType;
	}

	public void setOpType(String opType) {
		this.opType = opType;
	}

	public TypesData getOpTypeDesc() {
		return opTypeDesc;
	}

	public void setOpTypeDesc(TypesData opTypeDesc) {
		this.opTypeDesc = opTypeDesc;
	}

	public String getManhourType() {
		return manhourType;
	}

	public void setManhourType(String manhourType) {
		this.manhourType = manhourType;
	}

	public TypesData getManhourTypeDesc() {
		return manhourTypeDesc;
	}

	public void setManhourTypeDesc(TypesData manhourTypeDesc) {
		this.manhourTypeDesc = manhourTypeDesc;
	}

	public Float getActualWork() {
		return actualWork;
	}

	public void setActualWork(Float actualWork) {
		this.actualWork = actualWork;
	}

	public Float getPreopTime() {
		return preopTime;
	}

	public void setPreopTime(Float preopTime) {
		this.preopTime = preopTime;
	}

	public Float getRunTime() {
		return runTime;
	}

	public void setRunTime(Float runTime) {
		this.runTime = runTime;
	}

	public String getDispatchType() {
		return dispatchType;
	}

	public void setDispatchType(String dispatchType) {
		this.dispatchType = dispatchType;
	}

	public TypesData getDispatchTypeDesc() {
		return dispatchTypeDesc;
	}

	public void setDispatchTypeDesc(TypesData dispatchTypeDesc) {
		this.dispatchTypeDesc = dispatchTypeDesc;
	}

	public Float getApplyWork() {
		return applyWork;
	}

	public void setApplyWork(Float applyWork) {
		this.applyWork = applyWork;
	}

}